
var frontBaseUrl = "http://localhost:5500";
var backBaseUrl = "http://localhost:8080";
layui.use('element', function () {
    var element = layui.element;
})
function mdToHtml(content){
    const testView = editormd.markdownToHTML("content-markdown", {});
}



function loadData() {
    loadBoardMessage(getQueryVariable('id'));
    loadPrevious(getQueryVariable('id'));
}

function loadBoardMessage(id) {
    $.ajax({
        url: backBaseUrl + '/board-message/one',
        method: 'POST',
        data: {
            "id": id
        },
        crossDomain: true,
        xhrFields: { withCredentials: true },
        success: function (msg) {
            let data = msg.data.data;
            console.log(data);
            console.log(data.title);
            $(".bc-nav-now").append(data.title)
            $(".title h2").text(data.title);
            $("#author").text(data.authorName);
            $("#create-time").text("于    " + data.createTime);
            console.log(data.createTime)
            $("#read-count").append(data.readCount);
            $("#content-md-output").append(data.content);
            mdToHtml();
        }, error: function (error) {
            layer.msg("公告信息获取失败~将在3秒后返回公告栏");
            window.setTimeout(function (){
                window.location.href='./list.html';
            },3000);

        }
    })
}

function loadPrevious(id) {
    $.ajax({
        url: backBaseUrl + '/board-message/prev-next',
        method: 'POST',
        data: {
            "id": id
        },
        crossDomain: true,
        xhrFields: { withCredentials: true },
        success: function (msg) {
            let data = msg.data;
            console.log(data);
            if(data.prev !== null){
                let prev = $("#prev-btn");
                prev.attr("href","./detail.html?id=" + data.prev.id);
                prev.text("上一条：" + data.prev.title);
            }
            if(data.next !== null){
                let next = $("#next-btn");
                next.attr("href","./detail.html?id=" + data.next.id);
                next.text("下一条：" + data.next.title);
            }
        }, error: function (error) {
            layer.msg("公告获取失败~")
        }
    })
}